package com.qzh.baseStruct;

import org.apache.commons.math3.exception.NullArgumentException;

/**
 * 数字计算模拟
 */
@Deprecated
public class Decimal {
    //正负
    private boolean positive;
    //整数部分
    private char[] big;
    //小数部分
    private char[] small;
    //精度，也就是小数部分的位数
    private int scale;
    public Decimal(String numberString) throws Exception {
        //将字符型数字转为decimal存储的数字
       StringChange(numberString);


    }

    /**
     * 解析字符串
     * @param numberString
     */
    private void StringChange(String numberString) throws Exception {
        if(numberString.length() == 0||numberString==null){
            throw new Exception("参数为空");
        }
        //使用正则解析是否是合法数据
        String regex = "^[-+]?\\\\d+(\\\\.\\\\d+)?$";
        if(numberString.matches(regex)){
           //先判断正负号，然后再去除正负号
            if(numberString.charAt(0)=='+'){
                positive = true;
                numberString = numberString.substring(1);
            }
            if((numberString.charAt(0)>='1'&&numberString.charAt(0)<='9')){
                positive = true;

            }
            if(numberString.charAt(0)=='-'){
                positive = false;
                numberString = numberString.substring(1);
            }
            //默认为两位小数，如果没有小数部分
            if(!numberString.contains(".")){
                numberString = numberString + ".00";
            }
            String[] number = numberString.split("\\.");
        }
        else{
            throw new Exception("参数不合格");
        }
    }

    @Override
    public String toString() {
        return big +"." + small;
    }
}
